package volkov.ja;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import volkov.ja.pages.TestBase;
import volkov.ja.util.TestLogger;

public class MovieSearchNegativeTest1 extends TestBase {
	private static TestLogger LOG;

	@BeforeClass
	public void prepareTest() {
		LOG = new TestLogger(MovieSearchNegativeTest1.class, getSessionId());
		loginTestApplication();
	}

	@Test
	public void testMovieSearchNegative2() throws Exception {
		String titleFull = "The Spring Sun of Jamaica";
		LOG.info("Go to the movies list");
		driver.get(baseUrl + "#!/sort/name%20asc/");
		driver.findElement(By.id("q")).clear();
		By byResults = By.cssSelector(".movie_box");
		// save old element to check its state later
		WebElement contentOld = driver.findElement(byResults);
		LOG.info("Start search of \"" + titleFull + "\"");
		driver.findElement(By.id("q")).sendKeys(titleFull + Keys.RETURN);
		getUpdatedElement(byResults, contentOld,
				"Result list wasn't updated after the search");
		// check results
		LOG.info("Check that no movies are found with the query \"" + titleFull
				+ "\"");
		checkElementIsAbsent(byResults,
				"Error: Uexpected movies were found with the query \"" + titleFull
						+ "\"");
	}

}
